package com.tuantuan.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tuantuan.dao.ClassrequireDao;
import com.tuantuan.model.Classrequire;
import com.tuantuan.service.ClassrequireService;
/**
 * 班级基本资料控制层
 * @author Administrator
 *
 */
@Controller
public class ClassrequireController {

	@Autowired
	private ClassrequireDao claRequire;
	
	@Autowired
	private ClassrequireService classrequireService;
	
	/**
	 * 分页查询班级数据
	 * @param request
	 * @param response
	 * @param clr
	 * @return 查询分页结果集（班级数据）
	 */
	@RequestMapping("/classrequire/queryClassrequire.do")
	@ResponseBody
	public Map<String, Object> queryByPage(HttpServletRequest request,HttpServletResponse response,Classrequire clr){
		Map<String, Object> map = new HashMap<String, Object>();
		Classrequire c = claRequire.queryClassrequire(clr);
		map.put("page", c);
		return map;
	}
	
	/**
	 * 新增班级数据
	 * @param request
	 * @param response
	 * @param clr
	 * @return
	 */
	@RequestMapping("/classrequire/addClassrequire")
	@ResponseBody
	public String addClassrequire(HttpServletRequest request,Classrequire classrequire){
		
		//ModelAndView retMap = new ModelAndView("/classrequire/addClassrequire");
		//retMap.addObject("resStr", classrequireService.addClassrequire(classrequire));
		return classrequireService.addClassrequire(classrequire);
	}
	
	/**
	 * 获取单个班级数据（更新）
	 * @param request
	 * @param classId
	 * @return
	 */
	@RequestMapping("/classrequire/toUpdateClassrequire.do")
	public String updateClassrequireView(HttpServletRequest request, HttpServletResponse response, int classId){
		Classrequire cla = new Classrequire();
		//ModelAndView retMap = new ModelAndView("/classrequire/updateCLassrequireView");
		cla.setClassId(classId);
		//retMap.addObject("classrequire", claRequire.queryClassrequireById(cla));
		//return retMap;
		request.setAttribute("classrequire", claRequire.queryClassrequireById(cla));
		return "classrequire/classrequireView";
	}
	/**
	 * 更新班级资料
	 * @param request
	 * @param response
	 * @param classrequire
	 * @return
	 */
	
	@RequestMapping("/classrequire/updateClassrequire.do")
	@ResponseBody
	public String updateClassrequire(HttpServletRequest request,HttpServletResponse response,Classrequire classrequire){
		String flag = classrequireService.updateClassrequire(classrequire);
		return flag;

	}
	/**
	 * 删除班级资料（单条）
	 * @param request
	 * @param classId 
	 * @param pageCounts 删除记录当前页数
	 * @param pageCounts 删除操作的当前页数
	 * @return
	 */
	@RequestMapping("/classrequire/deleteClassrequire.do")
	private String deleteClassrequire(HttpServletRequest request, int classId,int pageCounts){
		String flag  = classrequireService.deleteClassrequire(classId);
		request.setAttribute("flag", flag);
		request.setAttribute("pageCounts", pageCounts);
		return "classrequire/classrequire";
	}
	
}
